<template>
	<view class="Global">
		<!-- <image class="imagepage" src="/static/background@2x.png" mode=""></image> -->
		<bgImage></bgImage>
		<MyNav :title="title" bgColor="" :backIcon="isback"></MyNav>



<!--		<view class="contentCenter">
			<view class="contentCenterTop">
				<text class="contentCenterTopText">默认打印所有扎，也可设置打印份数</text>
				<text class="contentCenterTopText">和页面打印范围，页面不一定和扎号相同</text>
			</view>
			<view class="contentCenterInner">

				<view class="contentCenterInnerItem" v-for="(item,index) in listData">

					<view class="contentCenterInnerItemTop">
						<text class="contentCenterInnerItemText">{{item.title}}</text>
						<input class="contentCenterInnerItemInput" type="text" :value="item.value" />
					</view>
					<view class="line" v-if="index< listData.length-1"></view>
				</view>

			</view>
			<view class="contentCenterBottom">
				<text class="contentCenterBottomText">共1页，共{{printDataList.length}}份</text>
			</view>
		</view>-->


    <!-- 列表数据  start-->
    <view class="listDataOut">

      <view class="listDataInner" >

        <view class="listDataInnerTop">
          <view class="listDataInnerTopLeft">
            <image class="listDataInnerTopLeftImg" v-if="itemdata.styleImgs!=''" :src="apiUrl+itemdata.styleImgs" mode=""></image>
            <image class="listDataInnerTopLeftImg" v-else src="/static/cuttingorder/cloth.png" mode=""></image>
          </view>
          <view class="listDataInnerTopRight">
            <text class="listDataInnerTopRightText">订单编号：{{itemdata.orderCode}}</text>
            <text class="listDataInnerTopRightText">款式：{{itemdata.styleName}}</text>
            <text class="listDataInnerTopRightText">日期：{{itemdata.createTime}}</text>
            <text class="listDataInnerTopRightText" v-if="itemdata.status=='0'">状态：未生产</text>
            <text class="listDataInnerTopRightText" v-if="itemdata.status=='1'">状态：生产中</text>
            <text class="listDataInnerTopRightText" v-if="itemdata.status=='2'">状态：生产完成</text>
          </view>
        </view>


        <view class="progress-box_out">

          <progress class="progress-box_progress" :percent="itemdata.percent" activeColor="#0081FF"
                    backgroundColor="#ECF5FD" stroke-width="4" active='true' />
          <text class="progress-box_text">完成度 </text>
          <text class="progress-box_text1">{{itemdata.percent}}%</text>
        </view>

      </view>

    </view>

    <!-- 列表数据  end-->

<!--    <scroll-view scroll-y="true" :style="'height:'+scrollViewHeight+'px'">-->

    <view class="contentCountTimeNew">
      <view class="contentCenterInnerListItemContent2">
        <view class="contentCountTime">
          <!-- 列表标题 -->

          <view class="titleStyleNew">
            <text class="titleStyleNumNew">操作</text>
            <text class="titleStyleNumNew">序号</text>
            <text class="titleStyleNumNew">颜色</text>
            <text class="titleStyleNumNew">尺码</text>
            <text class="titleStyleNumNew">扎号</text>
            <text class="titleStyleNumNew">数量</text>
          </view>

          <scroll-view scroll-y="true" class="titleStyleTitleNew">
            <!-- 列表内容 -->
            <view v-for="(item,index) in printDataList" >
              <view class="titleStyleListNew" v-if="index%2==0">
                <button type="warn" size="mini" @click="printOne(item,index)">打印</button>
                <text class="titleStyleNumListNew">{{index+1}}</text>
                <text class="titleStyleNumListNew">{{item.colors}}</text>
                <text class="titleStyleNumListNew">{{item.sizes}}</text>
                <text class="titleStyleNumListNew">{{index+1}}</text>
                <text class="titleStyleNumListNew">{{item.quantity}}</text>
              </view>
              <view class="titleStyleListElseNew" v-if="index%2!=0">
                <button type="warn" size="mini" @click="printOne(item,index)">打印</button>
                <text class="titleStyleNumListNew">{{index+1}}</text>
                <text class="titleStyleNumListNew">{{item.colors}}</text>
                <text class="titleStyleNumListNew">{{item.sizes}}</text>
                <text class="titleStyleNumListNew">{{index+1}}</text>
                <text class="titleStyleNumListNew">{{item.quantity}}</text>
              </view>
            </view>

          </scroll-view>

        </view>
      </view>
    </view>


<!--    </scroll-view>-->
    <view class="listDataOutBottom">
    <view class="listDataInnerBottom" id="mainBottom">
		<view class="connectDevice" >
			<text class="connectDeviceText" v-if="BLEInformation.name==''||BLEInformation.name==undefined">暂无已配对设备</text>
			<text class="connectDeviceText" v-else>已连接设备：{{BLEInformation.name}}</text>
		</view>

		<view class="loginContent">

			<button @click="printAll()" style="color:#ffffff" class="login" type="warn">{{login}}</button>
			<button @click="settingPrint()" style="color:#ffffff" class="login2" type="default">设置打印机</button>
		</view>
    </view>
    </view>


<!--		<view class="bottomBtnContent">-->

<!--			<text class="bottomBtnContentText" @click="labelTest">打印测试</text>-->
<!--			<text class="bottomBtnContentText" @click="queryStatus">状态检测</text>-->
<!--			<text class="bottomBtnContentText" @click="settingPrint">设置打印机</text>-->
<!--		</view>-->




	</view>
</template>

<script>
	import MyNav from '@/components/customnavbar.vue'
	import bgImage from '@/components/backgroundImage.vue'
	import tsc from "../../../components/utils/tsc";
  import {getOrderPrint} from '@/pages/api/api.js'
  import config from "@/pages/api/config";

	export default {
		components: {
			MyNav,
			bgImage
		},
		data() {
			return {
				login: '全部打印',

				title: '打印菲票',
        apiUrl: config.apiUrl,
				isback: true,


				listData: [

					{
						title: '开始页面',
						value: '1'
					},
					{
						title: '结束页面',
						value: '1'
					},
					{
						title: '打印份数',
						value: '1'
					}
				],
				/**
				 * 页面的初始数据
				 */
				data: {
					looptime: 0,
					currentTime: 1,
					lastData: 0,
					oneTimeData: 0,
					buffSize: [],
					buffIndex: 0, //发送字节数下标
					printNum: [],
					printNumIndex: 0,
					printerNum: 1,
					currentPrint: 1,
					isLabelSend: false,
					isQuery: false,
					imageSrc: '/static/logo.png',
					jpgSrc: '/static/logo.png',
					canvasWidth: 100,
					canvasHeight: 100,
					jpgWidth: 200,
					jpgHeight: 200,
				},
				BLEInformation: {
					platform: "",
					deviceId: "",
					writeCharaterId: "",
					writeServiceId: "",
					notifyCharaterId: "",
					notifyServiceId: "",
					readCharaterId: "",
					readServiceId: "",
				},

				// 小票打印内容
				printData: {
					orderNo: "20241223H1S4",
					num: "1床",
					style: "标准款",
					color: "黄色",
					size: "S",
					zhaNum: "1",
					goodsNum: "10",
					qrCode: "123456",
					tips: "好好用"
				},
        printDataList: [],
        orderId: '',
        tenantId: '',
        storeId: '',
        scrollViewHeight: 0,
        mainTop: '',
        bottomTop: '',
        itemdata: {},
			}
		},
    onShow: function (){
      console.log('bluetooth', uni.getStorageSync('bluetooth'))
      this.BLEInformation = uni.getStorageSync('bluetooth')
      if(Object.keys(this.BLEInformation).length!==0){
        this.bindViewTap(this.BLEInformation)
      }
    },
    onLoad: function(option) {
      let item = JSON.parse(decodeURIComponent(option.item));
      console.log('item', item)
      this.itemdata = item
      if(item && item.type!='one'){
        this.orderId = item.orderId
        this.tenantId = item.tenantId
        this.storeId = item.storeId
        this.getOrderPrint()
      }else {
        this.printDataList = []
        this.printDataList.push(item)
        this.listData.forEach(item=>{
          if(item.title=='结束页面'){
            item.value = this.printDataList.length
          }

        })
      }

    },
		onReady: function() {
      // 获取距离顶部的距离
      let query = uni.createSelectorQuery().in(this);
			var list = []
			var numList = []
			var j = 0
			for (var i = 20; i < 200; i += 10) {
				list[j] = i;
				j++
			}
			for (var i = 1; i < 10; i++) {
				numList[i - 1] = i
			}
			this.data.buffSize = list
			this.data.oneTimeData = list[0]
			this.data.printNum = numList
			this.data.printerNum = numList[0]
			this.initPhoto();
      query.select('#mainBottom').boundingClientRect(data => {
        this.bottomTop = data.top
        // console.log('2底部距离', this.bottomTop);

        this.scrollViewHeight = this.bottomTop - this.mainTop
        // console.log('可滚动距离', this.scrollViewHeight);
      }).exec();
		},
		methods: {

      getOrderPrint(){
        getOrderPrint(this.orderId).then(res=>{
          console.log('getOrderPrint',res);
          if(res.code==200){
            this.printDataList = res.data
            // this.data.printerNum = this.printDataList.length
            this.listData.forEach(item=>{
              if(item.title=='结束页面'){
                item.value = this.printDataList.length
              }

            })
          }
        })
      },
			settingPrint() {
				uni.navigateTo({
					url: '/subPackA/cuttingOrder/setUpThePrinter/setUpThePrinter',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			initPhoto: function() { //初始化画布数据
				//创建一个png格式
				var that = this
				const ctx_out = uni.createCanvasContext('canvasOut', this);
				var png = that.data.imageSrc;
				uni.getImageInfo({
					src: png,
					success(res) {

						that.data.canvasWidth = res.width
						that.data.canvasHeight = res.height
						console.log("画布宽度" + res.width, "画布高度" + res.height);
						// ctx_out.setFillStyle('#ffffff')
						// ctx_out.setStrokeStyle('rgba(1,1,1,0)')
						// ctx_out.fill()
						//ctx_out.drawImage(png, 0, 0, res.width, res.height);
						ctx_out.drawImage(png, 0, 0);
						ctx_out.draw();
					}
				})
				//创建一个jpg格式图片
				const ctx_jpg = uni.createCanvasContext('canvasJPG', this);
				var jpg_width = that.data.jpgWidth;
				var jpg_height = that.data.jpgHeight;
				var img = that.data.jpgSrc;
				uni.getImageInfo({
					src: img,
					success(res) {

						that.data.jpgWidth = res.width
						that.data.jpgHeight = res.height
						console.log("JPG画布宽度" + res.width, "JPG画布高度" + res.height);
						ctx_jpg.drawImage(img, 0, 0, res.width, res.height);
						ctx_jpg.draw();
					}
				})
			},
      printOne(row,index){
        if(this.BLEInformation.deviceId==''){
          uni.showToast({
            title: '暂无已配对设备',
            icon: 'none',
          })
        }
        let i = 0;

        let that = this
        let command = tsc.createNew()
        let printData = []

        row.zhaNum = index+1
        that.print(row,command)

        printData = printData.concat(command.getData())
        that.isLabelSend = true
        that.prepareSend(printData)
      },
      printAll(){
        if(this.BLEInformation.deviceId==''){
          uni.showToast({
            title: '暂无已配对设备',
            icon: 'none',
          })
        }
        let i = 0;

        let that = this
        let command = tsc.createNew()
        let printData = []
        this.printDataList.forEach(item=>{
          i++
          item.zhaNum = i;
          that.print(item,command)
        })
        printData = printData.concat(command.getData())
        that.isLabelSend = true
        that.prepareSend(printData)
      },
      async print(data,command) { //标签测试

        var that = this;
        var canvasWidth = that.data.canvasWidth
        var canvasHeight = that.data.canvasHeight

        // var command = tsc.createNew()
        command.setStripper("ON")

        // command.setHome()
        command.setCls() //清除缓冲区，防止下一个没生效
        command.setSize(30, 70) //设置标签大小，单位mm.具体参数请用尺子量一下
        // command.setSize(58, 65) //设置标签大小，单位mm.具体参数请用尺子量一下
        // command.setSize(30, 65) //设置标签大小，单位mm.具体参数请用尺子量一下
        // command.setSize(40, 80) //设置标签大小，单位mm.具体参数请用尺子量一下
        // command.setGap(0) //设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
        command.setCls() //清除缓冲区

        command.setGap(20)

        command.setText(15, 15, "TSS24.BF2", 0, 1, 1, "订单:" + data.orderCode) //绘制文字
        command.setText(15, 50, "TSS24.BF2", 0, 1, 1, "扎号:" + data.zhaNum) //绘制文字
        command.setText(15, 85, "TSS24.BF2", 0, 1, 1, "款号:" + data.styleName) //绘制文字
        command.setText(15, 120, "TSS24.BF2", 0, 1, 1, "颜色:" + data.colors ) //绘制文字
        command.setText(15, 155, "TSS24.BF2", 0, 1, 1, "尺码:" + data.sizes) //绘制文字
        command.setText(15, 185, "TSS24.BF2", 0, 1, 1,  "件数:" + data.quantity) //绘制文字
        command.setQrcode(35, 215, "L", 6, "A", data.id) //绘制一个二维码
        command.setText(15, 365, "TSS24.BF2", 0, 1, 1, "公司名称:" + data.tips) //绘制文字
        command.setPagePrint() //执行打印指令
        // that.isLabelSend = true
        // that.prepareSend(command.getData())
      },
			labelTest: function() { //标签测试
        if(this.BLEInformation.deviceId==''){
          uni.showToast({
            title: '暂无已配对设备',
            icon: 'none',
          })
        }
				var that = this;
				var canvasWidth = that.data.canvasWidth
				var canvasHeight = that.data.canvasHeight

				var command = tsc.createNew()
				command.setStripper("ON")

				// command.setHome()
				command.setCls() //清除缓冲区，防止下一个没生效
        command.setSize(30, 70) //设置标签大小，单位mm.具体参数请用尺子量一下
        // command.setSize(30, 65) //设置标签大小，单位mm.具体参数请用尺子量一下
        // command.setSize(40, 80) //设置标签大小，单位mm.具体参数请用尺子量一下
				// command.setGap(0) //设置两个标签之间的间隙，单位mm.具体参数请用尺子量一下
				command.setCls() //清除缓冲区

				command.setGap(20)
				// command.setHome()
				// command.setBox(10, 10, 464, 230, 5) //绘制一个边框
				// command.setBar(10, 75, 455, 5); //绘制一条黑线
				/* 	command.setText(120, 20, "TSS24.BF2", 0, 1, 1, "订单:" + that.printData.orderNo) //绘制文字
				  command.setText(120, 70, "TSS24.BF2", 0, 1, 1, "床号:" + that.printData.num) //绘制文字
				  command.setText(120, 120, "TSS24.BF2", 0, 1, 1, "款号:" + that.printData.style) //绘制文字
				  command.setText(120, 160, "TSS24.BF2", 0, 1, 1, "颜色:" + that.printData.color + " " + "尺码:" + that
				    .printData.size) //绘制文字
				  command.setText(120, 200, "TSS24.BF2", 0, 1, 1, "扎号:" + that.printData.zhaNum + " " + "件数:" + that
				    .printData.goodsNum) //绘制文字

				  command.setQrcode(150, 240, "L", 6, "A", "http://www.howbest.cn/cn/") //绘制一个二维码   */
				command.setText(15, 15, "TSS24.BF2", 0, 1, 1, "订单:" + that.printData.orderNo) //绘制文字
				command.setText(15, 50, "TSS24.BF2", 0, 1, 1, "床号:" + that.printData.num+ " " +"扎号:" + that.printData.zhaNum) //绘制文字
				command.setText(15, 85, "TSS24.BF2", 0, 1, 1, "款号:" + that.printData.style) //绘制文字
				command.setText(15, 120, "TSS24.BF2", 0, 1, 1, "颜色:" + that.printData.color ) //绘制文字
				command.setText(15, 155, "TSS24.BF2", 0, 1, 1, "尺码:" + that.printData.size) //绘制文字
				command.setText(15, 185, "TSS24.BF2", 0, 1, 1, "件数:" + that.printData.goodsNum) //绘制文字

				command.setQrcode(35, 215, "L", 6, "A", "http://www.howbest.cn/cn/") //绘制一个二维码
				// command.setPrint(1)
				// command.setCut("BATCH")
				command.setText(15, 365, "TSS24.BF2", 0, 1, 1, "公司名称:" + that.printData.tips) //绘制文字
				command.setPagePrint() //执行打印指令
				that.isLabelSend = true
				that.prepareSend(command.getData())
			},
			prepareSend: function(buff) {
				//准备发送，根据每次发送字节数来处理分包数量
				//console.log(buff)
				var that = this
				var time = that.data.oneTimeData
				var looptime = parseInt(buff.length / time);
				var lastData = parseInt(buff.length % time);
				//console.log(looptime + "---" + lastData)


				that.data.looptime = looptime + 1
				that.data.lastData = lastData
				that.data.currentTime = 1
				that.Send(buff)
			},
			Send: function(buff) { //分包发送
				/* uni.showModal({
				  title: '',
				  content: JSON.stringify(buff),
				  showCancel: false,
				  cancelText: '',
				  confirmText: '打印数据',
				  success: res => {},
				  fail: () => {},
				  complete: () => {}
				}); */
				var that = this
				var currentTime = that.data.currentTime
				var loopTime = that.data.looptime
				var lastData = that.data.lastData
				var onTimeData = that.data.oneTimeData
				var printNum = that.data.printerNum
				var currentPrint = that.data.currentPrint
				var buf
				var dataView
				if (currentTime < loopTime) {
					buf = new ArrayBuffer(onTimeData)
					dataView = new DataView(buf)
					for (var i = 0; i < onTimeData; ++i) {
						dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
					}
				} else {
					buf = new ArrayBuffer(lastData)
					dataView = new DataView(buf)
					for (var i = 0; i < lastData; ++i) {
						dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
					}
				}
				console.log("第" + currentPrint + "次发送数据大小为：" + buf.byteLength)
				uni.writeBLECharacteristicValue({
					deviceId: that.BLEInformation.deviceId,
					serviceId: that.BLEInformation.writeServiceId,
					characteristicId: that.BLEInformation.writeCharaterId,
					value: buf,
					success: function(res) {
            uni.showLoading({
              title: '正在打印中',
            })
						//console.log(res)
					},
					fail: function(e) {
						uni.showToast({
							title: '打印第' + currentPrint + '张失败',
							icon: 'none',
						})

						//console.log(e)
					},
					complete: function() {
						currentTime++
						if (currentTime <= loopTime) {

							that.data.currentTime = currentTime
							that.Send(buff)
						} else {
              uni.showToast({
                title: '打印完成',
              })
							if (currentPrint == printNum) {

								that.data.looptime = 0
								that.data.lastData = 0
								that.data.currentTime = 1
								that.data.isLabelSend = false
								that.data.currentPrint = 1

							} else {
								currentPrint++
								that.data.currentPrint = currentPrint
								that.data.currentTime = 1
								that.Send(buff)
							}
						}
					}
				})
			},
			queryStatus: function() {
        //查询打印机状态
        if(this.BLEInformation.deviceId==''){
          uni.showToast({
            title: '暂无已配对设备',
            icon: 'none',
          })
        }
				var that = this
				var buf;
				var dateView;
				/*
				n = 1：传送打印机状态
				n = 2：传送脱机状态
				n = 3：传送错误状态
				n = 4：传送纸传感器状态
				*/
				buf = new ArrayBuffer(5)
				dateView = new DataView(buf)
				dateView.setUint8(0, 27)
				dateView.setUint8(1, 33)
				dateView.setUint8(2, 63)
				dateView.setUint8(3, 13)
				dateView.setUint8(4, 10)
				uni.writeBLECharacteristicValue({
					deviceId: that.BLEInformation.deviceId,
					serviceId: that.BLEInformation.writeServiceId,
					characteristicId: that.BLEInformation.writeCharaterId,
					value: buf,
					success: function(res) {
						console.log("发送成功")

						that.data.isQuery = true
					},
					fail: function(e) {
						uni.showToast({
							title: '发送失败',
							icon: 'none',
						})
						//console.log(e)
						return;
					},
					complete: function() {

					}
				})

				uni.notifyBLECharacteristicValueChange({
					deviceId: that.BLEInformation.deviceId,
					serviceId: that.BLEInformation.notifyServiceId,
					characteristicId: that.BLEInformation.notifyCharaterId,
					state: true,
					success: function(res) {
						uni.onBLECharacteristicValueChange(function(r) {
							console.log(
								`characteristic ${r.characteristicId} has changed, now is ${r}`
							)
							var result = that.ab2hex(r.value)
							console.log("返回" + result)
							var tip = ''
							if (result == 0) { //正常
								tip = "正常"
							} else if (result == 4) { //缺纸
								tip = "缺纸"
							} else if (result == 5) { //开盖、缺纸
								tip = "开盖、缺纸"
							} else if (result == 41) {
								tip = "开盖"
							} else if (result == 40) { //其他错误
								tip = "其他错误"
							} else { //未处理错误
								tip = "未知错误"
							}
							uni.showModal({
								title: '打印机状态',
								content: tip,
								showCancel: false
							})

						})
					},
					fail: function(e) {
						uni.showModal({
							title: '打印机状态',
							content: '获取失败',
							showCancel: false
						})
						console.log(e)
					},
					complete: function(e) {

						that.data.isQuery = false
						console.log("执行完成")
					}
				})
			},
			// ArrayBuffer转16进度字符串示例
			ab2hex(buffer) {
				var hexArr = Array.prototype.map.call(
					new Uint8Array(buffer),
					function(bit) {
						return ('00' + bit.toString(16)).slice(-2)
					}
				)
				return hexArr.join('');
			},
      //校验蓝牙连接
      bindViewTap(e) {
        var that = this
        uni.stopBluetoothDevicesDiscovery({
          success(res) {
            console.log(res)
          },
        })
        that.serviceId=0
        that.writeCharacter=false
        that.readCharacter=false
        that.notifyCharacter=false

        // console.log(e.currentTarget.dataset.title)
        uni.showLoading({
          title: '正在连接',

        })
        uni.createBLEConnection({
          deviceId: e.deviceId,
          success(res) {
            console.log(res)
            that.BLEInformation.deviceId=e.deviceId
            that.BLEInformation.name=e.name
            that.getSeviceId(e.deviceId)

          },
          fail(e) {
            that.BLEInformation.deviceId = ''
            that.BLEInformation.name = ''
            uni.setStorageSync('bluetooth',that.BLEInformation)
            uni.showModal({
              title: '提示',
              content: '蓝牙连接失败',
              showCancel: false
            })
            console.log(e)
            uni.hideLoading()
          },
          complete(e) {
            console.log(e)
          }
        })
      },
      getSeviceId(e) {
        var that = this
        uni.getBLEDeviceServices({
          deviceId: e,
          success(res) {
            console.log(res)
            that.getCharacteristics(res.services)
          },
          fail(e) {
            console.log(e)
            that.BLEInformation.deviceId = ''
            that.BLEInformation.name = ''
            uni.setStorageSync('bluetooth',this.BLEInformation)
            uni.showModal({
              title: '蓝牙调用失败',
              content: JSON.stringify(e),
              showCancel: false,
              cancelText: '',
              confirmText: '确认',
              success: res => {},
              fail: () => {},
              complete: () => {}
            });
          },
          complete(e) {
            console.log(e)
          }
        })
      },
      getCharacteristics(e) {
        var that = this
        var list = e
        var num = that.serviceId
        var write = that.writeCharacter
        var read = that.readCharacter
        var notify = that.notifyCharacter

        uni.getBLEDeviceCharacteristics({
          deviceId: that.BLEInformation.deviceId,
          serviceId: list[num].uuid,
          success(res) {
            console.log(res)
            for (var i = 0; i < res.characteristics.length; ++i) {
              var properties = res.characteristics[i].properties
              var item = res.characteristics[i].uuid
              if (!notify) {
                if (properties.notify) {
                  that.BLEInformation.notifyCharaterId = item
                  that.BLEInformation.notifyServiceId = list[num].uuid
                  notify = true
                }
              }
              if (!write) {
                if (properties.write) {
                  that.BLEInformation.writeCharaterId = item
                  that.BLEInformation.writeServiceId = list[num].uuid
                  write = true
                }
              }
              if (!read) {
                if (properties.read) {
                  that.BLEInformation.readCharaterId = item
                  that.BLEInformation.readServiceId = list[num].uuid
                  read = true
                }
              }
            }
            if (!write || !notify || !read) {
              num++
              that.setData({
                writeCharacter: write,
                readCharacter: read,
                notifyCharacter: notify,
                serviceId: num
              })
              if (num == list.length) {
                that.BLEInformation.deviceId = ''
                that.BLEInformation.name = ''
                uni.setStorageSync('bluetooth',that.BLEInformation)
                uni.showModal({
                  title: '提示',
                  content: '找不到该读写的特征值',
                  showCancel: false
                })
              } else {
                that.getCharacteristics(e)
              }
            } else {
              uni.showToast({
                title: '蓝牙连接成功',
              })
              // that.openControl()
              uni.setStorageSync("bluetooth", that.BLEInformation)
              console.log('bluetooth',uni.getStorageSync('bluetooth'))
            }
          },
          fail(e) {
            console.log(e)
            that.BLEInformation.deviceId = ''
            that.BLEInformation.name = ''
            uni.setStorageSync('bluetooth',that.BLEInformation)
            uni.showModal({
              title: '蓝牙连接失败',
              content: JSON.stringify(e),
              showCancel: false,
              cancelText: '',
              confirmText: '确认',
              success: res => {},
              fail: () => {},
              complete: () => {}
            });
          },
          complete(e) {
            console.log("write:" + that.BLEInformation.writeCharaterId)
            console.log("read:" + that.BLEInformation.readCharaterId)
            console.log("notify:" + that.BLEInformation.notifyCharaterId)
          }
        })
      },
		}
	}
</script>

<style>
	.imagepage {

		background-size: cover;
		background-repeat: no-repeat;
		background-position: center center;
		position: absolute;
		z-index: -1;
		left: 0;
		right: 0;
		bottom: 0;
		right: 0;
		width: 100%;
		height: 100%;

	}

	.bottomBtnContentText {
		display: flex;
		justify-content: center;
		align-items: center;

		width: 210rpx;
		height: 100rpx;
		background: #FFFFFF;

		border-radius: 20rpx;


		font-family: HarmonyOS Sans SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #0081FF;
		line-height: 30rpx;

	}

	.bottomBtnContent {

		display: flex;
		justify-content: space-evenly;
		align-items: center;
		width: 100%;
		margin-top: 30rpx;
		margin-bottom: 30rpx;

		position: absolute;
		bottom: 10rpx;
	}

	.connectDeviceText {
		display: flex;
		justify-content: center;
		align-items: center;




		border-radius: 20rpx;


		font-family: HarmonyOS Sans SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #666666;
		line-height: 30rpx;
	}

	.connectDevice {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		bottom: 155rpx;
	}

	.loginContent {
		display: flex;
		/*flex-direction: column;*/
		flex-direction: row; /* 改为水平排列 */
		align-items: center;
		justify-content: center;
		width: 690rpx;

		position: absolute;
		bottom: 40rpx;
    gap: 20rpx; /* 可选：添加按钮间距 */

	}

  .login {
    display: flex;
    justify-content: center;
    margin-top: 40rpx;
    align-items: center;
    text-align: center;
    font-family: HarmonyOS Sans SC;
    font-weight: 400;
    font-size: 28rpx;
    color: #FFFFFF;
    line-height: 30rpx;

    width: 690rpx;
    height: 100rpx;
    /*background: linear-gradient(90deg, #45A8FF, #0AE1C6);*/
    border-radius: 20rpx;
  }

  .login2 {
    display: flex;
    justify-content: center;
    margin-top: 40rpx;
    align-items: center;
    text-align: center;
    font-family: HarmonyOS Sans SC;
    font-weight: 400;
    font-size: 28rpx;
    color: #FFFFFF;
    line-height: 30rpx;

    width: 690rpx;
    height: 100rpx;
    background: linear-gradient(90deg, #45A8FF, #0AE1C6);
    border-radius: 20rpx;
  }




	.line {
		width: 100%;
		height: 1rpx;
		background: #F9FCFF;


	}

	.contentCenterInnerItemInput {
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: HarmonyOS Sans SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #333333;


		width: 100rpx;
		margin-right: 20rpx;
		height: 100%;

	}

	.contentCenterInnerItemText {

		display: flex;
		align-items: center;
		justify-content: center;
		font-family: HarmonyOS Sans SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #333333;

		margin-left: 20rpx;
		height: 100%;
	}

	.contentCenterInnerItemTop {
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-direction: row;
		width: 100%;
		height: 100%;


	}

	.contentCenterInnerItem {
		display: flex;
		justify-content: space-between;
		align-items: center;
		flex-direction: column;
		width: 100%;
		height: 70rpx;

	}

	.contentCenterInner {

		width: 630rpx;
		height: 200rpx;
		background: #F5F7F9;
		border-radius: 20rpx;
		margin-top: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}

	.contentCenterTopText {

		display: flex;
		justify-content: center;
		align-items: center;
		font-family: HarmonyOS Sans SC;
		font-weight: bold;
		font-size: 28rpx;
		color: #333333;

	}

	.contentCenterBottomText {
		font-family: HarmonyOS Sans SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #333333;
		line-height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;



	}



	.contentCenterBottom {

		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		margin-top: 0rpx;

		width: 100%;
	}

	.contentCenterTop {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		margin-top: 30rpx;
		width: 100%;
	}

	.contentCenter {

		width: 690rpx;
		height: 440rpx;
		background: #FFFFFF;

		border-radius: 30rpx;

		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
  .titleStyleNumListNew {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 115rpx;
    height: 100%;
    font-size: 24rpx;
    color: #333333;

    text-align: left;
    font-style: normal;
    text-transform: none;
    white-space: nowrap;
  }
  .titleStyleNumNew {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 115rpx;
    height: 100%;
    font-size: 24rpx;
    color: #FFFFFF;

    text-align: center;
    font-style: normal;
    text-transform: none;

    white-space: nowrap;
  }

  .titleStyleTitleNew {
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: 100%;
    height: 800rpx;
    background: #FFFFFF;
    border-radius: 0rpx 0rpx 30rpx 30rpx;
    /*border-left: 1px solid #000000;*/
    /*border-right: 1px solid #000000;*/
    /*border-bottom: 1px solid #000000;*/
  }

  .titleStyleListElseNew {
    display: flex;
    justify-content: center;
    align-items: center;

    width: 100%;
    height: 80rpx;
    background: #F9FCFF;
  }

  .titleStyleListNew {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #FFFFFF;
    width: 100%;
    height: 80rpx;

  }
  .titleStyleNew {
    display: flex;
    justify-content: center;
    align-items: center;

    width: 100%;
    height: 80rpx;
    background: #0081FF;
    border-radius: 30rpx 30rpx 0rpx 0rpx;
    margin-top: 42rpx
  }
  .contentCountTime {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 100%;
  }
  .contentCenterInnerListItemContent2 {
    display: flex;
    justify-content: center;
    flex-direction: column;
  }
  .contentCountTimeNew {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 690rpx;

    white-space: nowrap;

    overflow-x: auto;
    display: -webkit-box;
    overflow-y: hidden;
  }

  .listDataOut {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 750rpx;
    margin-top: 30rpx;
    margin-bottom: -20rpx;
  }
  .listDataOutBottom {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 750rpx;
    margin-top: 30rpx;
    margin-bottom: -20rpx;
  }
  .listDataInner {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;

    width: 690rpx;
    height: 295rpx;
    background: #FFFFFF;
    border-radius: 30rpx;



  }
  .listDataInnerBottom {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;

    width: 690rpx;
    height: 170rpx;
    background: #FFFFFF;
    border-radius: 30rpx;



  }
  .listDataInnerTop {
    position: relative;
    display: flex;
    flex-direction: row;

    display: flex;
    justify-content: left;
    width: 100%;
    /* background: #0AE1C6; */


  }
  .listDataInnerTopLeft {
    width: 190rpx;
    height: 190rpx;
    background: #ECF5FD;
    border-radius: 20rpx;
    display: flex;
    align-items: center;
    justify-content: center;

    margin-right: 30rpx;
    margin-left: 30rpx;
    margin-top: 30rpx;
  }
  .listDataInnerTopLeftImg {
    width: 188rpx;
    height: 148rpx;

  }

  .listDataInnerTopRight {
    display: flex;
    flex-direction: column;
    align-items: left;


    margin-top: 30rpx;
  }
  .listDataInnerTopRightText {
    font-family: HarmonyOS Sans SC;
    font-weight: 600;
    font-size: 24rpx;
    color: #333333;
    line-height: 50rpx;
  }
  .listDataInnerTopRightImgBg {
    display: flex;
    justify-content: center;
    align-items: center;

    position: absolute;
    top: 30rpx;
    right: 30rpx;
  }
  .listDataInnerTopRightImg {
    width: 50rpx;
    height: 50rpx;
    padding: 10rpx;

  }
  .progress-box_out {
    margin-top: 20rpx;
    display: flex;
    flex-direction: row;

    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;

    border-radius: 5rpx;

    /* background-color: #333333; */
  }
  .progress-box_progress {
    display: flex;
    width: 380rpx;
    height: 10rpx;
    border-radius: 5rpx;
  }
  .progress-box_text {
    color: #666666;
    margin-left: 30rpx;
    font-size: 24rpx;
    font-weight: 600;
  }
  .progress-box_text1 {
    color: #0081FF;
    margin-left: 10rpx;
    font-size: 24rpx;
  }
</style>
